<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改密码</title>
<link rel="icon" href="<c:url value='/imgs/logo.ico' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/css/index.css' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/css/add.css' />" />
<script type="text/javascript" charset="utf-8" src="<c:url value='/scripts/jquery-2.1.0.js'/>"></script>
</head>
<body>
	<div class="container">
		<%@ include file="/jsps/top.jsp"%>
		<div class="main">
			<form class="form updatepw">
				<h2>修改密码</h2>
				<table>
					<tr>
						<td><label>旧&nbsp;&nbsp;密&nbsp;&nbsp;码：</label></td>
						<td>
							<input class="txt" type="password" name="opw" placeholder="请输入旧密码" maxlength="15"/><span class="must">*</span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error1"></span>
						</td>
					</tr>
					<tr>
						<td><label>新&nbsp;&nbsp;密&nbsp;&nbsp;码：</label></td>
						<td>
							<input class="txt" type="password" name="npw" placeholder="请输入新密码" maxlength="15"/><span class="must">*</span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error2"></span>
						</td>
					</tr>
					<tr>
						<td><label>确认密码：</label></td>
						<td>
							<input class="txt" type="password" name="rpw" placeholder="请输入确认密码" maxlength="15"/><span class="must">*</span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<span class="error error3"></span>
						</td>
					</tr>
				</table>
				<input class="btn updateBtn" type="button" value="修改"/>
				<input class="btn" type="reset" value="重置"/>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		$(function(){
			//标题
			$(".top .title").click(function(){
				location.href="<c:url value='/index.jsp'/>";
			});			
			
			//修改按钮
			$(".main .form .updateBtn").click(function(){
				$(".main .form .error").text("");
				var opw = $("input[name='opw']").val();
				var npw = $("input[name='npw']").val();
				var rpw = $("input[name='rpw']").val();
				//var empid = ${sessionScope.employee.empid };
				
			//	alert(empid);
				if($.isEmptyObject(opw)||$.isEmptyObject(npw)||$.isEmptyObject(rpw)){
					alert("星号内容不能为空!");
				}else{
					$.ajax({
						type:"post",
						url:"<c:url value='/updatePw' />",
						data:{"opw":opw,"npw":npw,"rpw":rpw},
						dataType:"json",
						success:function(data){
							if(data.flag=="1"){
								if($.isEmptyObject(data.opw)){
									data.opw = "";
								}
								if($.isEmptyObject(data.npw)){
									data.npw = "";
								}
								if($.isEmptyObject(data.rpw)){
									data.rpw = "";
								}
								$(".main .form .error1").text(data.opw);
								$(".main .form .error2").text(data.npw);
								$(".main .form .error3").text(data.rpw);
							}else{
								alert("修改成功,3秒后将退出");
								setTimeout(function(){
									window.location.href="<c:url value='/quit' />";
								},3000);
							}	
						},
						error:function(){
							alert("操作失败，请重试!");
						}
					});
				}
			});
		});
	</script>
</body>
</html>